<?php

class LoginModule extends fvModule {
	
	function __construct() {
		$moduleName = strtolower ( substr ( __CLASS__, 0, - 6 ) );
		
		parent::__construct ( fvSite::$fvConfig->get ( "modules.{$moduleName}.smarty.template" ), fvSite::$fvConfig->get ( "modules.{$moduleName}.smarty.compile" ), fvSite::$Layoult );
	}
	
	function showIndex() {
		return $this->__display ( 'login_form.tpl' );
	}
	
	function showDeny() {
		return $this->__display ( "deny.tpl" );
	}
	
	function showBlock() {
		$LoggedUser = fvSite::$fvSession->get ( "login/loggedUser" );
		if ($LoggedUser) {
			$count_videos = VideoManager::getInstance()->getCount("user_id=".$LoggedUser->getPk());
			$count_images = ImageManager::getInstance()->getCount("user_id=".$LoggedUser->getPk());
			$count_feedbacks = FeedbackManager::getInstance()->getCount("user_id=".$LoggedUser->getPk());
			$this->__assign("VideoCount", $count_videos);
			$this->__assign("ImageCount", $count_images);
			$this->__assign("FeedbackCount", $count_feedbacks);
			$this->__assign("LoggedUser", $LoggedUser);
			return $this->__display ( "logged_block.tpl" );
		} else {
			$error = fvSite::$fvSession->get ( "ERROR_LOGIN" );
			fvSite::$fvSession->set ( "ERROR_LOGIN", NULL );
			$this->__assign("ERROR", $error);
			return $this->__display ( "login_block.tpl" );
		}
	}
	
	function showBlockLogged(){
		$LoggedUser = fvSite::$fvSession->get ( "login/loggedUser" );
		if ($LoggedUser) {
			return $this->__display ( "logged_info.tpl" );
		}
	}
	
	function showRegister() {
		$request = fvRequest::getInstance ();
		$this->__assign ( 'Error', fvSite::$fvSession->get ( 'ERROR' ) );
		$this->__assign ( 'm', $request->getRequestParameter ( 'm' ) );
		return $this->__display ( "register_error.tpl" );
	}
	
	function showForget() {
		$this->__assign ( 'Error', fvSite::$fvSession->get ( 'ERROR' ) );
		return $this->__display ( "forget.tpl" );
	}
}

?>
